//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "DefaultProbabilityTermStructure.h"
using namespace Cephei::QL::Termstructures;
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/DayCounter.h>
#include <gen/QL/Quote.h>
#include <gen/QL/TermStructure.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL;
#define HANDLE
#define ABSTRACT
#undef STRUCT
Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::CDefaultProbabilityTermStructure (boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure>& childNative, Object^ owner) : CTermStructure(CDefaultProbabilityTermStructure::typeid)
{
#ifdef HANDLE
	_phDefaultProbabilityTermStructure = NULL;
#endif
	_ppDefaultProbabilityTermStructure = &childNative;
    _ppTermStructure = new boost::shared_ptr<QuantLib::TermStructure> (boost::dynamic_pointer_cast<QuantLib::TermStructure> (*_ppDefaultProbabilityTermStructure));
}
Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::CDefaultProbabilityTermStructure (QuantLib::DefaultProbabilityTermStructure& childNative, Object^ owner) : CTermStructure(CDefaultProbabilityTermStructure::typeid)
{
#ifdef HANDLE
	_phDefaultProbabilityTermStructure = NULL;
#endif
	_ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (&childNative);
    _ppTermStructure = new boost::shared_ptr<QuantLib::TermStructure> (boost::dynamic_pointer_cast<QuantLib::TermStructure> (*_ppDefaultProbabilityTermStructure));
    _DefaultProbabilityTermStructureOwner = owner;
    _TermStructureOwner = owner;
}

Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::CDefaultProbabilityTermStructure (CDefaultProbabilityTermStructure^ copy) : CTermStructure(CDefaultProbabilityTermStructure::typeid)
{
#ifdef HANDLE
	_phDefaultProbabilityTermStructure = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (copy->GetShared());
        _ppTermStructure = new boost::shared_ptr<QuantLib::TermStructure> (boost::dynamic_pointer_cast<QuantLib::TermStructure> (*_ppDefaultProbabilityTermStructure));
    }
}
Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::CDefaultProbabilityTermStructure (System::Type^ t) : CTermStructure(CDefaultProbabilityTermStructure::typeid)
{
#ifdef HANDLE
	_phDefaultProbabilityTermStructure = NULL;
#endif
	if (!t->IsSubclassOf(CDefaultProbabilityTermStructure::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::CDefaultProbabilityTermStructure (QuantLib::Handle<QuantLib::DefaultProbabilityTermStructure>& childNative, Object^ owner)  : CTermStructure(CDefaultProbabilityTermStructure::typeid)
{
	_phDefaultProbabilityTermStructure = &childNative;
	_ppDefaultProbabilityTermStructure = &static_cast<boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure>>(childNative.currentLink());
    _ppTermStructure = new boost::shared_ptr<QuantLib::TermStructure> (boost::dynamic_pointer_cast<QuantLib::TermStructure> (*_ppDefaultProbabilityTermStructure));
    _DefaultProbabilityTermStructureOwner = owner;
}
Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::CDefaultProbabilityTermStructure (QuantLib::Handle<QuantLib::DefaultProbabilityTermStructure> childNative)  : CTermStructure(CDefaultProbabilityTermStructure::typeid)
{
	_phDefaultProbabilityTermStructure = &childNative;
	_ppDefaultProbabilityTermStructure = &static_cast<boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure>>(childNative.currentLink());
    _ppTermStructure = new boost::shared_ptr<QuantLib::TermStructure> (boost::dynamic_pointer_cast<QuantLib::TermStructure> (*_ppDefaultProbabilityTermStructure));
}
#endif
#ifdef STRUCT
Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::CDefaultProbabilityTermStructure (QuantLib::DefaultProbabilityTermStructure childNative)  : CTermStructure(CDefaultProbabilityTermStructure::typeid)
{
#ifdef HANDLE
	_phDefaultProbabilityTermStructure = NULL;
#endif
	_ppDefaultProbabilityTermStructure = new boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure> (new QuantLib::DefaultProbabilityTermStructure (childNative));
    _ppTermStructure = new boost::shared_ptr<QuantLib::TermStructure> (boost::dynamic_pointer_cast<QuantLib::TermStructure> (*_ppDefaultProbabilityTermStructure));
}
#endif

Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::~CDefaultProbabilityTermStructure ()
{
    if (_ppDefaultProbabilityTermStructure != NULL)
    {
	    delete _ppDefaultProbabilityTermStructure;
        _ppDefaultProbabilityTermStructure = NULL;
    }
}
Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::!CDefaultProbabilityTermStructure ()
{
    if (_ppDefaultProbabilityTermStructure != NULL)
    {
	    delete _ppDefaultProbabilityTermStructure;
    }
}
QuantLib::DefaultProbabilityTermStructure& Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::GetReference ()
{
    if (_ppDefaultProbabilityTermStructure == NULL) throw gcnew NativeNullException ();
	return **_ppDefaultProbabilityTermStructure;
}
boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure>& Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::GetShared ()
{
    if (_ppDefaultProbabilityTermStructure == NULL) throw gcnew NativeNullException ();
	return *_ppDefaultProbabilityTermStructure;
}
QuantLib::DefaultProbabilityTermStructure* Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::GetPointer ()
{
    if (_ppDefaultProbabilityTermStructure == NULL) throw gcnew NativeNullException ();
	return &**_ppDefaultProbabilityTermStructure;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::DefaultProbabilityTermStructure>& Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::GetHandle ()
{
	if (_phDefaultProbabilityTermStructure == NULL)
	{
		_phDefaultProbabilityTermStructure = new Handle<QuantLib::DefaultProbabilityTermStructure> (*_ppDefaultProbabilityTermStructure);
	}
	return *_phDefaultProbabilityTermStructure;
}
#endif
bool Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::HasNative () 
{
	return (_ppDefaultProbabilityTermStructure != NULL);
}

Double Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::DefaultDensity (Double t, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate)
{
    try
    {
        QuantLib::Time _t = (QuantLib::Time)ValueHelper::Convert (t);
        bool _extrapolate = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (extrapolate) ? (bool)ValueHelper::Convert (extrapolate->Value) : false); //9a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppDefaultProbabilityTermStructure)->defaultDensity ( _t,  _extrapolate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::DefaultProbability (Double t1, Double t2, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapo)
{
    try
    {
        QuantLib::Time _t1 = (QuantLib::Time)ValueHelper::Convert (t1);
        QuantLib::Time _t2 = (QuantLib::Time)ValueHelper::Convert (t2);
        bool _extrapo = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (extrapo) ? (bool)ValueHelper::Convert (extrapo->Value) : false); //9a
    	QuantLib::Probability _rv = (QuantLib::Probability)(*_ppDefaultProbabilityTermStructure)->defaultProbability ( _t1,  _t2,  _extrapo );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::DefaultProbability (DateTime d1, DateTime d2, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate)
{
    try
    {
        QuantLib::Date _d1 = (QuantLib::Date)ValueHelper::Convert (d1);
        QuantLib::Date _d2 = (QuantLib::Date)ValueHelper::Convert (d2);
        bool _extrapolate = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (extrapolate) ? (bool)ValueHelper::Convert (extrapolate->Value) : false); //9a
    	QuantLib::Probability _rv = (QuantLib::Probability)(*_ppDefaultProbabilityTermStructure)->defaultProbability ( _d1,  _d2,  _extrapolate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::DefaultProbability (Double t, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate)
{
    try
    {
        QuantLib::Time _t = (QuantLib::Time)ValueHelper::Convert (t);
        bool _extrapolate = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (extrapolate) ? (bool)ValueHelper::Convert (extrapolate->Value) : false); //9a
    	QuantLib::Probability _rv = (QuantLib::Probability)(*_ppDefaultProbabilityTermStructure)->defaultProbability ( _t,  _extrapolate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::DefaultProbability (DateTime d, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate)
{
    try
    {
        QuantLib::Date _d = (QuantLib::Date)ValueHelper::Convert (d);
        bool _extrapolate = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (extrapolate) ? (bool)ValueHelper::Convert (extrapolate->Value) : false); //9a
    	QuantLib::Probability _rv = (QuantLib::Probability)(*_ppDefaultProbabilityTermStructure)->defaultProbability ( _d,  _extrapolate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::IVector<DateTime>^ Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::JumpDates::get ()
{
    try
    {
    	std::vector<QuantLib::Date>& _rv = (std::vector<QuantLib::Date>&)(*_ppDefaultProbabilityTermStructure)->jumpDates ( );   
        Cephei::IVector<DateTime>^ _nrv = gcnew CoVector<DateTime> (gcnew CDateTimeVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::SurvivalProbability (Double t, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate)
{
    try
    {
        QuantLib::Time _t = (QuantLib::Time)ValueHelper::Convert (t);
        bool _extrapolate = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (extrapolate) ? (bool)ValueHelper::Convert (extrapolate->Value) : false); //9a
    	QuantLib::Probability _rv = (QuantLib::Probability)(*_ppDefaultProbabilityTermStructure)->survivalProbability ( _t,  _extrapolate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::SurvivalProbability (DateTime d, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate)
{
    try
    {
        QuantLib::Date _d = (QuantLib::Date)ValueHelper::Convert (d);
        bool _extrapolate = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (extrapolate) ? (bool)ValueHelper::Convert (extrapolate->Value) : false); //9a
    	QuantLib::Probability _rv = (QuantLib::Probability)(*_ppDefaultProbabilityTermStructure)->survivalProbability ( _d,  _extrapolate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::IVector<Double>^ Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::JumpTimes::get ()
{
    try
    {
    	std::vector<QuantLib::Time>& _rv = (std::vector<QuantLib::Time>&)(*_ppDefaultProbabilityTermStructure)->jumpTimes ( );   
        Cephei::IVector<Double>^ _nrv = gcnew CoVector<Double> (gcnew CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Termstructures::IDefaultProbabilityTermStructure^ Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::Update::get ()
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
    	(*_ppDefaultProbabilityTermStructure)->update ( );
    	return this;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::DefaultDensity (DateTime d, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate)
{
    try
    {
        QuantLib::Date _d = (QuantLib::Date)ValueHelper::Convert (d);
        bool _extrapolate = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (extrapolate) ? (bool)ValueHelper::Convert (extrapolate->Value) : false); //9a
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppDefaultProbabilityTermStructure)->defaultDensity ( _d,  _extrapolate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::HazardRate (Double t, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate)
{
    try
    {
        QuantLib::Time _t = (QuantLib::Time)ValueHelper::Convert (t);
        bool _extrapolate = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (extrapolate) ? (bool)ValueHelper::Convert (extrapolate->Value) : false); //9a
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppDefaultProbabilityTermStructure)->hazardRate ( _t,  _extrapolate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Termstructures::CDefaultProbabilityTermStructure::HazardRate (DateTime d, Microsoft::FSharp::Core::FSharpOption<Boolean>^ extrapolate)
{
    try
    {
        QuantLib::Date _d = (QuantLib::Date)ValueHelper::Convert (d);
        bool _extrapolate = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (extrapolate) ? (bool)ValueHelper::Convert (extrapolate->Value) : false); //9a
    	QuantLib::Rate _rv = (QuantLib::Rate)(*_ppDefaultProbabilityTermStructure)->hazardRate ( _d,  _extrapolate );   
        Double _nrv = (Double)ValueHelper::Convert (_rv);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Termstructures::CDefaultProbabilityTermStructureVector::CDefaultProbabilityTermStructureVector ()
{
#ifdef STRUCT
	_pVValue = NULL;
#endif
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
}
Cephei::QL::Termstructures::CDefaultProbabilityTermStructureVector::~CDefaultProbabilityTermStructureVector ()
{
#ifdef STRUCT
	if (_pVValue != NULL) delete _pVValue;
	_pVValue = NULL;
#endif   
	if (_pVBoost != NULL) delete _pVBoost;
	_pVBoost = NULL;
#ifdef HANDLE
	if (_pVHand != NULL) delete _pVHand;
	_pVHand = NULL;
#endif
}
Cephei::QL::Termstructures::CDefaultProbabilityTermStructureVector::!CDefaultProbabilityTermStructureVector ()
{
#ifdef STRUCT
	if (_pVValue != NULL) delete _pVValue;
#endif   
	if (_pVBoost != NULL) delete _pVBoost;
#ifdef HANDLE
	if (_pVHand != NULL) delete _pVHand;
#endif
}
#ifdef STRUCT
Cephei::QL::Termstructures::CDefaultProbabilityTermStructureVector::CDefaultProbabilityTermStructureVector (std::vector<QuantLib::DefaultProbabilityTermStructure>& vec, Object^ owner)
{
#ifdef STRUCT
	_pVValue = NULL;
#endif
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
	_pVValue = &vec;
	_owner = owner;
}
Cephei::QL::Termstructures::CDefaultProbabilityTermStructureVector::CDefaultProbabilityTermStructureVector (std::vector<QuantLib::DefaultProbabilityTermStructure> vec)
{
#ifdef STRUCT
	_pVValue = NULL;
#endif
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
	_pVValue = new std::vector<QuantLib::DefaultProbabilityTermStructure> (vec);
}
#endif
Cephei::QL::Termstructures::CDefaultProbabilityTermStructureVector::CDefaultProbabilityTermStructureVector (std::vector<boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure>>& vec, Object^ owner)
{
#ifdef STRUCT
	_pVValue = NULL;
#endif
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
	 _pVBoost = &vec;
	_owner = owner;
}
#ifdef HANDLE
Cephei::QL::Termstructures::CDefaultProbabilityTermStructureVector::CDefaultProbabilityTermStructureVector (std::vector<QuantLib::Handle<QuantLib::DefaultProbabilityTermStructure>>& vec, Object^ owner)
{
#ifdef STRUCT
	_pVValue = NULL;
#endif
	_pVBoost = NULL;
#ifdef HANDLE
	_pVHand = NULL;
#endif
	 _pVHand = &vec;
	_owner = owner;
}
#endif

int Cephei::QL::Termstructures::CDefaultProbabilityTermStructureVector::Count::get ()
{
#ifdef STRUCT
	if (_pVValue != NULL) 
	{
		return _pVValue->size();
	}
#endif    
	if (_pVBoost != NULL)
	{
		return _pVBoost->size ();
	}
#ifdef HANDLE
	if (_pVHand != NULL)
	{
		return _pVHand->size ();
	}
#endif
	return 0;		// should never happen
}
Cephei::QL::Termstructures::IDefaultProbabilityTermStructure^ Cephei::QL::Termstructures::CDefaultProbabilityTermStructureVector::default::get (int index) 
{
#ifdef STRUCT
	if (_pVValue != NULL) 
	{
    	if ((size_t)index >= _pVValue->size()) throw gcnew RangeException ();
		QuantLib::DefaultProbabilityTermStructure& native = (*_pVValue)[index];
		return gcnew CDefaultProbabilityTermStructure (native, this);
	}
#endif    
	if (_pVBoost != NULL)
	{
    	if ((size_t)index >= _pVBoost->size()) throw gcnew RangeException ();
		QuantLib::DefaultProbabilityTermStructure& native = *(*_pVBoost)[index];
		return gcnew CDefaultProbabilityTermStructure (native, this);
	}
#ifdef HANDLE
	if (_pVHand != NULL)
	{
    	if ((size_t)index >= _pVHand->size()) throw gcnew RangeException ();
		QuantLib::DefaultProbabilityTermStructure& native = *((*_pVHand)[index].currentLink ());
		return gcnew CDefaultProbabilityTermStructure (native, this);
	}
#endif
	return nullptr;		// can never be the case
}
void Cephei::QL::Termstructures::CDefaultProbabilityTermStructureVector::default::set (int index, Cephei::QL::Termstructures::IDefaultProbabilityTermStructure^ value) 
{
#ifdef STRUCT
	if (_pVValue != NULL)
	{
		if (_pVValue->size() <= (size_t)index)
		{
			// can't happen because vectors are filled from List<> sequentially
			if (_pVValue->size() < (size_t)index)
			{
				throw gcnew RangeException ();
			}
			_pVValue->push_back (dynamic_cast<CDefaultProbabilityTermStructure^>(value)->GetReference ());
		}
        else
        {
            QuantLib::DefaultProbabilityTermStructure& c = (*_pVValue)[index];
            c = dynamic_cast<CDefaultProbabilityTermStructure^>(value)->GetReference ();
        }
	}
#endif   
	if (_pVBoost != NULL)
	{
		if (_pVBoost->size() <= (size_t)index)
		{
			// can't happen because vectors are filled from List<> sequentially
			if (_pVBoost->size() < (size_t)index)
			{
				throw gcnew RangeException ();
			}
			_pVBoost->push_back (dynamic_cast<CDefaultProbabilityTermStructure^>(value)->GetShared ());
		}
		boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure>& c = (*_pVBoost)[index];
		c = dynamic_cast<CDefaultProbabilityTermStructure^>(value)->GetShared ();
	}
#ifdef HANDLE
	if (_pVHand != NULL)
	{
		if (_pVHand->size() <= (size_t)index)
		{
			// can't happen because vectors are filled from List<> sequentially
			if (_pVHand->size() < (size_t)index)
			{
				throw gcnew RangeException ();
			}
			_pVHand->push_back (QuantLib::Handle<QuantLib::DefaultProbabilityTermStructure> ());
		}
		QuantLib::Handle<QuantLib::DefaultProbabilityTermStructure>& c = (*_pVHand)[index];
		boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure>& b = static_cast<boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure>>(c.currentLink());
		b = dynamic_cast<CDefaultProbabilityTermStructure^>(value)->GetShared ();
	}
#endif
}
Cephei::Generic::ICell<Cephei::QL::Termstructures::IDefaultProbabilityTermStructure^>^ Cephei::QL::Termstructures::CDefaultProbabilityTermStructureVector::CItem::get (int index) 
{
	return CellBuilder::Instance->Create<IDefaultProbabilityTermStructure^> (dynamic_cast<IDefaultProbabilityTermStructure^>(default[index]));
}

void Cephei::QL::Termstructures::CDefaultProbabilityTermStructureVector::CItem::set (int index, Cephei::Generic::ICell<Cephei::QL::Termstructures::IDefaultProbabilityTermStructure^>^ value) 
{
	default[index] = safe_cast<IDefaultProbabilityTermStructure^>(value->Value);
}
#ifdef STRUCT
std::vector<QuantLib::DefaultProbabilityTermStructure>& Cephei::QL::Termstructures::CDefaultProbabilityTermStructureVector::GetReference ()
{
	 return *_pVValue;
}
#endif

std::vector<boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure>>& Cephei::QL::Termstructures::CDefaultProbabilityTermStructureVector::GetShared ()
{
	return *_pVBoost;
}

#ifdef HANDLE
std::vector<QuantLib::Handle<QuantLib::DefaultProbabilityTermStructure>>& Cephei::QL::Termstructures::CDefaultProbabilityTermStructureVector::GetHandle ()
{
	return *_pVHand;
}
#endif
bool Cephei::QL::Termstructures::CDefaultProbabilityTermStructureVector::PrepareFeature (NativeFeature feature)
{
	switch (feature)
	{
#ifdef STRUCT
		case NativeFeature::Value :
			if (_pVValue == NULL)
			{
				_pVValue = new std::vector<QuantLib::DefaultProbabilityTermStructure> ();
				return true;
			}
			break;
#endif
        case NativeFeature::shared_ptr :
			if (_pVBoost == NULL)
			{
				_pVBoost = new std::vector<boost::shared_ptr<QuantLib::DefaultProbabilityTermStructure>> ();
				return true;
			}
			break;
#ifdef HANDLE
        case NativeFeature::Handle :
            if (_pVHand == NULL)
            {
                _pVHand = new std::vector<QuantLib::Handle<QuantLib::DefaultProbabilityTermStructure>> ();
                return true;
            }
            break;
#endif
	}
	return false;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

/* <summary>Create a single dimension array of DefaultProbabilityTermStructure that can be passed into other function </summary> */
IVector<Cephei::QL::Termstructures::IDefaultProbabilityTermStructure^>^ Cephei::QL::Termstructures::CDefaultProbabilityTermStructure_Factory::CreateVector ()
 {
	 return gcnew CoVector<IDefaultProbabilityTermStructure^> (gcnew CDefaultProbabilityTermStructureVector ());
 }
IVector<Cephei::QL::Termstructures::IDefaultProbabilityTermStructure^>^ Cephei::QL::Termstructures::CDefaultProbabilityTermStructure_Factory::CreateVector (System::Collections::Generic::IEnumerable<IDefaultProbabilityTermStructure^>^ source)
 {
	 return gcnew CoVector<IDefaultProbabilityTermStructure^> (source, gcnew CDefaultProbabilityTermStructureVector ());
 }
/* <summary>Create a single dimension array of DefaultProbabilityTermStructure with change events</summary> */
Cephei::Generic::ICell<IVector<Cephei::Generic::ICell<Cephei::QL::Termstructures::IDefaultProbabilityTermStructure^>^>^>^ Cephei::QL::Termstructures::CDefaultProbabilityTermStructure_Factory::CreateCellVector ()
 {
	 return CellBuilder::Instance->Create<IVector<Cephei::Generic::ICell<Cephei::QL::Termstructures::IDefaultProbabilityTermStructure^>^>^> (gcnew CoCellVector<Cephei::Generic::ICell<Cephei::QL::Termstructures::IDefaultProbabilityTermStructure^>^> (gcnew CDefaultProbabilityTermStructureVector ()));
 }
Cephei::Generic::ICell<IVector<Cephei::Generic::ICell<Cephei::QL::Termstructures::IDefaultProbabilityTermStructure^>^>^>^ Cephei::QL::Termstructures::CDefaultProbabilityTermStructure_Factory::CreateCellVector (System::Collections::Generic::IEnumerable<Cephei::Generic::ICell<Cephei::QL::Termstructures::IDefaultProbabilityTermStructure^>^>^ source)
 {
	 return CellBuilder::Instance->Create<IVector<Cephei::Generic::ICell<Cephei::QL::Termstructures::IDefaultProbabilityTermStructure^>^>^> (gcnew CoCellVector<Cephei::Generic::ICell<Cephei::QL::Termstructures::IDefaultProbabilityTermStructure^>^> (source, gcnew CDefaultProbabilityTermStructureVector ()));
 }

